unit uPosVenda;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ATStandard, Grids, DBGrids, DB, DBClient,dbtables;

type
  TfrmPos_Venda = class(TForm)
    CDSPosVenda: TClientDataSet;
    CDSPosVendaData: TDateField;
    CDSPosVendaNF: TStringField;
    CDSPosVendaAtendende: TStringField;
    CDSPosVendaObs1: TStringField;
    CDSPosVendaObs2: TStringField;
    CDSPosVendaEntidade: TStringField;
    CDSPosVendaCod: TStringField;
    dsPosVenda: TDataSource;
    dbgPosVda: TDBGrid;
    ATLabel1: TATLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormActivate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure dbgPosVdaKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
    ppEntidade: String;
    procedure FazConsulta(p_Entidade: String);
  end;

var
  frmPos_Venda: TfrmPos_Venda;

implementation

uses clsPos_Venda, Dm, clsEntidade;

var
 PosVenda: TPosVenda;

{$R *.dfm}

{ TfrmPos_Venda }

procedure TfrmPos_Venda.FazConsulta(p_Entidade: String);
var
 tq: TQuery;
begin
  CDSPosVenda.Close;
  CDSPosVenda.CreateDataSet;
  CDSPosVenda.Open;
  tq:=Tquery.create(dmint);
  tq.databasename:=dm.dmint.db.databasename;
  tq.active:=False;
  PosVenda.Consultar(tq,p_Entidade);
  while not tq.Eof do begin
   CDSPosVenda.Append;
   CDSPosVendaCod.Value      := tq.FieldByName('PosV_Codigo').AsString;
   CDSPosVendaEntidade.Value := tq.FieldByName('Ent_Codigo').AsString;
   CDSPosVendaNF.Value       := tq.FieldByName('Nota_Numero').AsString;
   CDSPosVendaData.Value     := tq.FieldByName('PosV_Data').AsDateTime;
   CDSPosVendaAtendende.Value:= tq.FieldByName('PosV_Contato').AsString;
   CDSPosVendaObs1.Value     := tq.FieldByName('PosV_Obs1').AsString;
   CDSPosVendaObs2.Value     := tq.FieldByName('PosV_Obs2').AsString;
   CDSPosVenda.Post;
   tq.next;
  end;
end;

procedure TfrmPos_Venda.FormCreate(Sender: TObject);
begin
 PosVenda:= TPosVenda.Create;
end;

procedure TfrmPos_Venda.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 PosVenda.Free;
end;

procedure TfrmPos_Venda.FormActivate(Sender: TObject);
var
 Entidade: TEntidade;
begin
 Entidade:= TEntidade.Create;
 Entidade.Recuperar(ppEntidade);
 ATLabel1.Caption:= 'Entidade: '+ppEntidade+'-'+Entidade.Ent_Nome;
 Entidade.Free;
 FazConsulta(ppEntidade);
end;

procedure TfrmPos_Venda.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key = VK_ESCAPE then
  Close;
end;

procedure TfrmPos_Venda.dbgPosVdaKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key = VK_ESCAPE then
  Close;
end;

end.

